#ifndef EDITORBASE_H
#define EDITORBASE_H

#include "prep.h"

#include <wx/hashmap.h>
#include <wx/frame.h>
#include <wx/panel.h>
#include "globals.h"
#include "M_Code_exception.h"

class wxMenu;
class EditorBase;
struct EditorBaseInternalData;
class cbDebuggerPlugin;

WX_DECLARE_HASH_MAP( int, EditorBase*, wxIntegerHash, wxIntegerEqual, SwitchToMap );


class EditorBase : public wxPanel {
    DECLARE_EVENT_TABLE()
  public:
    EditorBase( wxWindow* parent, const wxString& filename );
    virtual ~EditorBase();
    void operator=( M_Code_optional const EditorBase& rhs ) { m_Throw( _T( "不能分配一个EditorBase* !!!" ) ); }
    virtual const wxString& GetFilename() const { return m_Filename; }
    virtual void SetFilename( const wxString& filename ) { m_Filename = filename; }
    virtual const wxString& GetShortName() const { return m_Shortname; }
    virtual bool GetModified() const { return false; }
    virtual void SetModified( bool  = true ) {}
    virtual const wxString& GetTitle();
    virtual void SetTitle( const wxString& newTitle );
    virtual void Activate();
    virtual bool QueryClose();
    virtual bool Close();
    virtual bool Save() { return true; }
    virtual bool SaveAs() { return true; }
    virtual bool IsBuiltinEditor() const;
    virtual bool ThereAreOthers() const;
    virtual void DisplayContextMenu( const wxPoint& position, ModuleType type = mtUnknown );
    virtual bool VisibleToTree() const { return true; }
    virtual void GotoLine( int, bool  = true ) {}
    virtual void Undo() {}
    virtual void Redo() {}
    virtual void ClearHistory() {}
    virtual void GotoNextChanged() {}
    virtual void GotoPreviousChanged() {}
    virtual void SetChangeCollection( M_Code_optional bool collectChange ) {}
    virtual void Cut() {}
    virtual void Copy() {}
    virtual void Paste() {}
    virtual bool CanUndo() const { return false; }
    virtual bool CanRedo() const { return false; }
    virtual bool HasSelection() const { return false; }
    virtual bool CanPaste() const { return false; }
    virtual bool IsReadOnly() const { return false; }
    virtual void SetReadOnly( bool  = true ) {}
    virtual bool CanSelectAll() const { return false; }
    virtual void SelectAll() { return; }
    virtual bool IsContextMenuOpened() const;
  protected:
    virtual void InitFilename( const wxString& filename );
    virtual void AddToContextMenu( M_Code_optional wxMenu* popup, M_Code_optional ModuleType type ) {}
    virtual wxString CreateUniqueFilename();
    virtual bool OnBeforeBuildContextMenu( M_Code_optional const wxPoint& position, M_Code_optional ModuleType type ) { return true; }
    bool m_IsBuiltinEditor;
    wxString m_Shortname;
    wxString m_Filename;
    EditorBaseInternalData* m_pData;
  private:
    EditorBase( M_Code_unused const EditorBase& rhs );
    void OnContextMenuEntry( wxCommandEvent& event );
    void BasicAddToContextMenu( wxMenu* popup, ModuleType type );
    SwitchToMap m_SwitchTo;
    wxString m_WinTitle;
    wxString lastWord;
};

#endif
